/*------------------------------------------------------------------------------
 * PROJ : Prototype
 * NAME : sculove.spring.zzz.login.controller.LoginController.java
 *        
 * Copyright 2009 sculove All rights reserved
 *------------------------------------------------------------------------------
 */
package sculove.spring.zzz.login.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import sculove.spring.framework.common.AbstractController;
import sculove.spring.framework.exception.BizException;
import sculove.spring.zzz.login.model.UserDTO;
import sculove.spring.zzz.login.service.LoginService;

/**
 * <pre>
 * sculove.spring.zzz.login.controller.LoginController.java
 * 
 * TODO
 * 
 * </pre>
 * 
 * @date : 2009. 11. 20. 오후 11:56:50
 * @version :
 * @author : sculove
 */
@Controller
public class LoginController extends AbstractController {
	@Resource(name="zzz.loginService")
	private LoginService loginService=null;

	public LoginService getLoginService() {
		return loginService;
	}

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
 
	@RequestMapping(value="/zzz.login.htm")
	public ModelAndView login(@ModelAttribute("UserDTO") UserDTO dto, HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		if(loginService.login(request, dto)) {
			mav.setViewName("zzz/menu/MainFrame");				
		} else {
			//throw new BizException("COM.INF.001", "sample/form/Form");
			throw new BizException("COM.INF.001", "forward:/index.jsp");
		}
		return mav;
	}
	
	@RequestMapping(value="/zzz.logout.htm")
	public String logout(HttpServletRequest request) throws Exception {
		loginService.logout(request);
		return "forward:/index.jsp";
	}	
}
